"""
 Copyright 2020-present Open Networking Foundation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""

load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("@npm//@bazel/karma:index.bzl", "karma_web_test")

package(default_visibility = ["//:__subpackages__"])

exports_files(["lib/widget/panel.css"])

# We don't import from these, but the generated ngfactory code will
NG_FACTORY_ADDED_IMPORTS = [
    "@npm//@angular/animations",
    "@npm//@angular/forms",
]

ts_library(
    name = "gui2-fw-lib",
    srcs = glob(
        include = [
            "**/*.ts",
            "public_api.ts",
        ],
        exclude = [
            "**/*.spec.ts",
        ],
    ),
    angular_assets = glob([
        "lib/**/*.css",
        "lib/**/*.html",
    ]),
    module_name = "org_onosproject_onos/web/gui2-fw-lib",
    #    entry_point = ":public_api.ts",
    tsconfig = "//web/gui2:tsconfig.json",
    use_angular_plugin = True,
    deps = [
        "@npm//@angular/animations",
        "@npm//@angular/common",
        "@npm//@angular/compiler-cli",
        "@npm//@angular/core",
        "@npm//@angular/platform-browser",
        "@npm//@angular/router",
        "@npm//@bazel/typescript",
        "@npm//d3",
        "@npm//rxjs",
    ],
)

ts_library(
    name = "test_lib",
    testonly = 1,
    srcs = glob(
        include = ["**/*.spec.ts"],
        # TODO re-enable this test
        exclude = ["lib/nav/nav.service.spec.ts"],
    ),
    tsconfig = "//web/gui2:tsconfig-test",
    deps = [
        ":gui2-fw-lib",
        "@npm//@angular/common",
        "@npm//@angular/core",
        "@npm//@angular/forms",
        "@npm//@angular/platform-browser",
        "@npm//@angular/router",
        "@npm//@types/jasmine",
        "@npm//rxjs",
    ],
)

karma_web_test(
    name = "test-not-coverage",  # coverage is to avoid being picked up by 'ot' alias
    srcs = [
        # We are manaully adding the bazel generated named-UMD d3 bundle here as
        # named-UMD bundles for non-APF npm packages are not yet automatically added.
        # This file is generated by the npm_umd_bundle @npm//d3
        # rule that is setup by yarn_install.
    ],
    # do not sort
    bootstrap = [
        "@npm//:node_modules/zone.js/dist/zone-testing-bundle.js",
        "@npm//:node_modules/reflect-metadata/Reflect.js",
    ],
    config_file = "//web/gui2/src/main/webapp:karma.conf.js",
    tags = ["native"],
    runtime_deps = [
        "//web/gui2/src/main/webapp:initialize_testbed",
    ],
    deps = [
        ":test_lib",
        "//web/gui:src/main/webapp/data",
        "//web/gui2/src/main/webapp:d3_requirejs",
        "//web/gui2/src/main/webapp:rxjs_umd_modules",
        "@npm//@angular-devkit/build-angular",
        "@npm//karma-coverage-istanbul-reporter",
        "@npm//karma-jasmine-html-reporter",
    ],
)

filegroup(
    name = "extra_css",
    srcs = [
        "lib/widget/panel.css",
        "lib/widget/panel-theme.css",
        "lib/widget/table.css",
        "lib/widget/table.theme.css",
    ],
)
